using Newtonsoft.Json;
using System.Collections.Generic;

namespace BanZuiCloudControlAgent.Core.Mqtt.Models
{
    /// <summary>
    /// QQ账号信息模型
    /// </summary>
    public class QQAccountInfoModel
    {
        /// <summary>
        /// QQ号码
        /// </summary>
        [JsonProperty("qqNumber")]
        public string QQNumber { get; set; }

        /// <summary>
        /// QQ昵称
        /// </summary>
        [JsonProperty("nickname")]
        public string Nickname { get; set; }

        /// <summary>
        /// QQ状态
        /// </summary>
        [JsonProperty("status")]
        public int Status { get; set; }

        /// <summary>
        /// 登录时间戳（毫秒）
        /// </summary>
        [JsonProperty("loginTime")]
        public long LoginTime { get; set; }

        /// <summary>
        /// 是否为会员
        /// </summary>
        [JsonProperty("isVip")]
        public bool IsVip { get; set; }

        /// <summary>
        /// 会员等级
        /// </summary>
        [JsonProperty("vipLevel")]
        public int VipLevel { get; set; }

        /// <summary>
        /// 群数量
        /// </summary>
        [JsonProperty("groupCount")]
        public int GroupCount { get; set; }

        /// <summary>
        /// 好友数量
        /// </summary>
        [JsonProperty("friendCount")]
        public int FriendCount { get; set; }

        /// <summary>
        /// 额外信息
        /// </summary>
        [JsonProperty("extraInfo")]
        public Dictionary<string, object> ExtraInfo { get; set; }
    }

    /// <summary>
    /// QQ在线列表上报消息负载模型
    /// </summary>
    public class QQOnlineReportPayloadModel
    {
        /// <summary>
        /// 总QQ数量
        /// </summary>
        [JsonProperty("totalCount")]
        public int TotalCount { get; set; }

        /// <summary>
        /// 在线QQ列表
        /// </summary>
        [JsonProperty("onlineQQList")]
        public List<QQAccountInfoModel> OnlineQQList { get; set; }
    }

    /// <summary>
    /// QQ在线列表上报消息模型
    /// </summary>
    public class QQOnlineReportModel : BaseMessageModel
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public QQOnlineReportModel() : base()
        {
            MessageType = MessageTypeConstants.QQ_ONLINE_REPORT;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <param name="payload">QQ在线列表上报负载</param>
        public QQOnlineReportModel(string deviceCode, QQOnlineReportPayloadModel payload)
            : base(MessageTypeConstants.QQ_ONLINE_REPORT, deviceCode, payload)
        {
        }

        /// <summary>
        /// 获取QQ在线列表上报负载
        /// </summary>
        /// <returns>QQ在线列表上报负载</returns>
        public QQOnlineReportPayloadModel GetPayload()
        {
            return Payload as QQOnlineReportPayloadModel;
        }

        /// <summary>
        /// 创建QQ在线列表上报消息
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <param name="onlineQQList">在线QQ列表</param>
        /// <returns>QQ在线列表上报消息模型</returns>
        public static QQOnlineReportModel CreateQQOnlineReport(
            string deviceCode,
            List<QQAccountInfoModel> onlineQQList)
        {
            var payload = new QQOnlineReportPayloadModel
            {
                TotalCount = onlineQQList?.Count ?? 0,
                OnlineQQList = onlineQQList ?? new List<QQAccountInfoModel>()
            };

            return new QQOnlineReportModel(deviceCode, payload);
        }

        /// <summary>
        /// 创建空的QQ在线列表上报消息
        /// </summary>
        /// <param name="deviceCode">设备码</param>
        /// <returns>QQ在线列表上报消息模型</returns>
        public static QQOnlineReportModel CreateEmptyQQOnlineReport(string deviceCode)
        {
            var payload = new QQOnlineReportPayloadModel
            {
                TotalCount = 0,
                OnlineQQList = new List<QQAccountInfoModel>()
            };

            return new QQOnlineReportModel(deviceCode, payload);
        }
    }
} 